package com.tianqu.tms.entity;

import java.sql.Timestamp;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.dao.MarketCarServiceDao;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dto.MarketCarServiceDto;

public class MarketCarService extends ViewListManager {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long id;
	private String serial;
	private String checkImgPath;
	private int checkStatus;
	private String checkUser;
	private Timestamp checkTime;
	private Timestamp checkValidTime;
	private int isValid;
	private int checkPrice;
	private int transferPrice;
	private int isRebate;
	
	public static MarketCarService getInstance() {
		MarketCarService marketCarService = new MarketCarService();
		marketCarService.setExisting(false);
		return marketCarService;
	}
	/**
	 * @param carService
	 * @return
	 * @throws TmsDaoException
	 */
	public void updateCarServiceInfo(MarketCarService carService) throws TmsDaoException{
		MarketCarServiceDao marketCarServiceDao = (MarketCarServiceDao) TmsDao.getInstance(TmsDao.TMS_MARKET_CAR_SERVICE_INFO);		
		MarketCarServiceDto dto = new MarketCarServiceDto();
		dto.setSerial(carService.getSerial());
		dto.setCheckImgPath(carService.getCheckImgPath());
		dto.setCheckStatus(carService.getCheckStatus());
		dto.setCheckUser(carService.getCheckUser());
		dto.setCheckTime(carService.getCheckTime());
		dto.setCheckValidTime(carService.getCheckValidTime());
		dto.setIsValid(carService.getIsValid());
		marketCarServiceDao.updateCarServiceInfo(dto);
	}
	/**
	 * @param carService
	 * @return
	 * @throws TmsDaoException
	 */
	public void updateCarServiceAllInfo(MarketCarService carService) throws TmsDaoException{
		MarketCarServiceDao marketCarServiceDao = (MarketCarServiceDao) TmsDao.getInstance(TmsDao.TMS_MARKET_CAR_SERVICE_INFO);		
		MarketCarServiceDto dto = new MarketCarServiceDto();
		dto.setSerial(carService.getSerial());
		dto.setCheckStatus(carService.getCheckStatus());
		dto.setCheckImgPath(carService.getCheckImgPath());
		dto.setCheckUser(carService.getCheckUser());
		dto.setCheckTime(carService.getCheckTime());
		dto.setCheckValidTime(carService.getCheckValidTime());
		dto.setIsValid(carService.getIsValid());
		dto.setCheckPrice(carService.getCheckPrice());
		dto.setTransferPrice(carService.getTransferPrice());
		dto.setIsRebate(carService.getIsRebate());
		marketCarServiceDao.updateCarServiceAllInfo(dto);
	}
	
	public void updateIsRebate(int isRebate,String serial)  throws TmsDaoException{
		MarketCarServiceDao marketCarServiceDao = (MarketCarServiceDao) TmsDao.getInstance(TmsDao.TMS_MARKET_CAR_SERVICE_INFO);		
		marketCarServiceDao.updateIsRebate(isRebate,serial);
	}
	
	
	/**
	 * @param serial
	 * @return
	 * @throws TmsDaoException
	 */
	public boolean isExistCarServiceInfoBySerial(String serial) throws TmsDaoException{
		boolean result = false;
		MarketCarServiceDao marketCarServiceDao = (MarketCarServiceDao) TmsDao.getInstance(TmsDao.TMS_MARKET_CAR_SERVICE_INFO);
		result = marketCarServiceDao.isExistCarServiceInfoBySerial(serial);
		return result;
	}
	/**
	 * @param carService
	 * @return
	 * @throws TmsDaoException
	 */
	public void insertCarServiceInfo(MarketCarService carService)throws TmsDaoException{
		MarketCarServiceDao marketCarServiceDao = (MarketCarServiceDao) TmsDao.getInstance(TmsDao.TMS_MARKET_CAR_SERVICE_INFO);		
		MarketCarServiceDto dto = new MarketCarServiceDto();
		dto.setSerial(carService.getSerial());
		dto.setCheckImgPath(carService.getCheckImgPath());
		dto.setCheckStatus(carService.getCheckStatus());
		dto.setCheckUser(carService.getCheckUser());
		dto.setCheckTime(carService.getCheckTime());
		dto.setCheckValidTime(carService.getCheckValidTime());
		dto.setIsValid(carService.getIsValid());
		marketCarServiceDao.insertCarServiceInfo(dto);
	}
	/**
	 * @param serial
	 * @return
	 * @throws TmsDaoException
	 */
	public MarketCarService findCarServiceInfoBySerial(String serial) throws TmsDaoException{
		MarketCarService carService = new MarketCarService();
		MarketCarServiceDao marketCarServiceDao = (MarketCarServiceDao) TmsDao.getInstance(TmsDao.TMS_MARKET_CAR_SERVICE_INFO);
		MarketCarServiceDto dto = marketCarServiceDao.findCarServiceInfoBySerial(serial);
		if(dto != null){
			carService.setSerial(dto.getSerial());
			carService.setCheckImgPath(dto.getCheckImgPath());
			carService.setCheckPrice(dto.getCheckPrice());
			carService.setCheckStatus(dto.getCheckStatus());
			carService.setCheckUser(dto.getCheckUser());
			carService.setCheckTime(dto.getCheckTime());
			carService.setCheckValidTime(dto.getCheckValidTime());
			carService.setIsValid(dto.getIsValid());
			carService.setTransferPrice(dto.getTransferPrice());
			carService.setIsRebate(dto.getIsRebate());
		}
		return carService;
	}
	/**
	 * 插入库存车辆业务表
	 * @param carService
	 * @return
	 * @throws TmsDaoException
	 */
	public void insertCarServiceIsValid(MarketCarService carService)throws TmsDaoException{
		MarketCarServiceDao marketCarServiceDao = (MarketCarServiceDao) TmsDao.getInstance(TmsDao.TMS_MARKET_CAR_SERVICE_INFO);		
		MarketCarServiceDto dto = new MarketCarServiceDto();
		dto.setSerial(carService.getSerial());
		dto.setIsValid(carService.getIsValid());
		dto.setCheckStatus(carService.getCheckStatus());
		marketCarServiceDao.insertCarServiceIsValid(dto);
	}
	/**
	 * 更新库存车辆业务表
	 * @param carService
	 * @return
	 * @throws TmsDaoException
	 */
	public void updateCarServicePrice(MarketCarService carService)throws TmsDaoException{
		MarketCarServiceDao marketCarServiceDao = (MarketCarServiceDao) TmsDao.getInstance(TmsDao.TMS_MARKET_CAR_SERVICE_INFO);		
		MarketCarServiceDto dto = new MarketCarServiceDto();
		dto.setSerial(carService.getSerial());
		dto.setCheckPrice(carService.getCheckPrice());
		dto.setTransferPrice(carService.getTransferPrice());
		marketCarServiceDao.updateCarServicePrice(dto);
	}
	
	/**
	 * @param id the id to set
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * @return the id
	 */
	public long getId() {
		return id;
	}

	/**
	 * @param serial the serial to set
	 */
	public void setSerial(String serial) {
		this.serial = serial;
	}

	/**
	 * @return the serial
	 */
	public String getSerial() {
		return serial;
	}

	/**
	 * @param checkImgPath the checkImgPath to set
	 */
	public void setCheckImgPath(String checkImgPath) {
		this.checkImgPath = checkImgPath;
	}

	/**
	 * @return the checkImgPath
	 */
	public String getCheckImgPath() {
		return checkImgPath;
	}

	/**
	 * @param checkStatus the checkStatus to set
	 */
	public void setCheckStatus(int checkStatus) {
		this.checkStatus = checkStatus;
	}

	/**
	 * @return the checkStatus
	 */
	public int getCheckStatus() {
		return checkStatus;
	}

	/**
	 * @param checkUser the checkUser to set
	 */
	public void setCheckUser(String checkUser) {
		this.checkUser = checkUser;
	}

	/**
	 * @return the checkUser
	 */
	public String getCheckUser() {
		return checkUser;
	}

	/**
	 * @param checkTime the checkTime to set
	 */
	public void setCheckTime(Timestamp checkTime) {
		this.checkTime = checkTime;
	}

	/**
	 * @return the checkTime
	 */
	public Timestamp getCheckTime() {
		return checkTime;
	}

	/**
	 * @param checkValidTime the checkValidTime to set
	 */
	public void setCheckValidTime(Timestamp checkValidTime) {
		this.checkValidTime = checkValidTime;
	}

	/**
	 * @return the checkValidTime
	 */
	public Timestamp getCheckValidTime() {
		return checkValidTime;
	}

	/**
	 * @param isValid the isValid to set
	 */
	public void setIsValid(int isValid) {
		this.isValid = isValid;
	}

	/**
	 * @return the isValid
	 */
	public int getIsValid() {
		return isValid;
	}

	/**
	 * @param checkPrice the checkPrice to set
	 */
	public void setCheckPrice(int checkPrice) {
		this.checkPrice = checkPrice;
	}

	/**
	 * @return the checkPrice
	 */
	public int getCheckPrice() {
		return checkPrice;
	}
	/**
	 * @param transferPrice the transferPrice to set
	 */
	public void setTransferPrice(int transferPrice) {
		this.transferPrice = transferPrice;
	}
	/**
	 * @return the transferPrice
	 */
	public int getTransferPrice() {
		return transferPrice;
	}
	public int getIsRebate() {
		return isRebate;
	}
	public void setIsRebate(int isRebate) {
		this.isRebate = isRebate;
	}
	
}
